package com.ann.tes;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Demo {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void main(String[] args) throws Exception {
		Class cl = Class.forName("com.ann.tes.Child");
		boolean isExist = cl.isAnnotationPresent(Description.class);
		if (isExist) {
			// 类上的注解
			Description de = (Description) cl.getAnnotation(Description.class);
			System.out.println(de.value());
		}

		Method[] ms = cl.getMethods();
		for (Method m : ms) {
			boolean isMExist = m.isAnnotationPresent(Description.class);
			if (isMExist) {
				// 方法上的注解
				Description d = (Description) m.getAnnotation(Description.class);
				System.out.println(d.value());
			}
		}

		// 方法上的注解
		for (Method m : ms) {
			Annotation[] as = m.getAnnotations();
			for (Annotation a : as) {
				if (a instanceof Description) {
					Description d = (Description) a;
					System.out.println(d.value());
				}
			}
		}
	}

}
